import { Injectable } from '@nestjs/common';
import { ConfigService } from './config.service';

@Injectable()
export class UserService {
  constructor(private readonly configService: ConfigService) {}

  // 使用配置服务的方法
  getUserConfigInfo(): string {
    const apiKey = this.configService.getApiKey();
    const timeout = this.configService.getTimeout();
    const baseUrl = this.configService.getBaseUrl();

    return `API Key: ${apiKey}, Timeout: ${timeout}ms, Base URL: ${baseUrl}`;
  }

  // 模拟API调用，使用配置
  fetchUserData(userId: string): Promise<{ id: string; name: string; email: string }> {
    const baseUrl = this.configService.getBaseUrl();
    const timeout = this.configService.getTimeout();

    console.log(`Fetching user data from ${baseUrl}/users/${userId} with timeout ${timeout}ms`);

    // 模拟API请求
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          id: userId,
          name: 'John Doe',
          email: 'john.doe@example.com',
        });
      }, 1000);
    });
  }
}